package com.demo.shop.repository;

import com.demo.shop.bean.Article;
import com.demo.shop.utils.Pager;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository("articleMapper")
public interface ArticleMapper {

    /**
     * 获取产品列表
     * @param typeCode 一级分类 code
     * @param secondType 二级分类 code
     * @param title 查询关键字
     * @return
     */
    List<Article> searchArticles(@Param("typeCode") String typeCode,
                                 @Param("secondType") String secondType,
                                 @Param("title") String title,
                                 @Param("pager") Pager pager);

    /**
     * 查询记录总数
     * @param typeCode
     * @param secondType
     * @param title
     * @return
     */
    int count(@Param("typeCode") String typeCode,
              @Param("secondType") String secondType,
              @Param("title") String title);

    @Delete("delete from ec_article where id = #{id}")
    void deleteById(String id);

    @Select("select * from ec_article where id = #{id}")
    @ResultMap("articleResultMap")
    Article getArticleById(String id);


    void update(Article article);

    void save(Article article);
}
